<!--
 * Description: Tec新增页面
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Qiuxue.Wu
 * Date: 2020/06/24 09:28
-->

<template>
  <div>
    <!--数据表单-->
    <el-form label-width="120px" :model="formData" size="mini">
      <el-row>
        <!--料号-->
        <el-col :span="12">
          <el-form-item :label="$t('Pool.material')">
            <el-input v-model="formData.material" v-blur:material="formData" clearable />
          </el-form-item>
        </el-col>

        <!--料件描述-->
        <el-col :span="12">
          <el-form-item :label="$t('Pool.materialDescription')">
            <el-input
              v-model="formData.materialDescription"
              v-blur:materialDescription="formData"
              clearable
            />
          </el-form-item>
        </el-col>

        <!--料件分组-->
        <el-col :span="12">
          <el-form-item :label="$t('Pool.materialGroup')">
            <el-input v-model="formData.materialGroup" v-blur:materialGroup="formData" clearable />
          </el-form-item>
        </el-col>

        <!--专案名称-->
        <el-col :span="12">
          <el-form-item :label="$t('Pool.projectName')">
            <el-select v-model="formData.projectId" clearable filterable size="small">
              <el-option
                v-for="item in projectList"
                :key="item.projectId"
                :label="item.projectName"
                :value="item.projectId"
              />
            </el-select>
          </el-form-item>
        </el-col>

        <!--专案编号-->
        <el-col :span="12">
          <el-form-item :label="$t('Pool.projectId')">
            <el-input disabled :value="formData.projectId" />
          </el-form-item>
        </el-col>

        <!--Source Type-->
        <el-col :span="12">
          <el-form-item :label="$t('Pool.sourceType')">
            <el-input v-model="formData.sourceType" v-blur:sourceType="formData" clearable />
          </el-form-item>
        </el-col>

        <!--Tower-->
        <el-col :span="12">
          <el-form-item :label="$t('Pool.tower')">
            <el-input v-model="formData.tower" v-blur:tower="formData" clearable />
          </el-form-item>
        </el-col>

        <!--系统价格-->
        <el-col :span="12">
          <el-form-item :label="$t('Pool.pir')">
            <BaseInput
              v-model="formData.pir"
              v-blur:pir="formData"
              clearable
              :max="9999999999.99999999"
              :min="0"
              :placeholder="$t('input.placeholder')"
              :precision="4"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span style="display: block; text-align: center; margin-top: 5px">
      <!--取消按钮-->
      <el-button size="medium" @click="cancel">{{ $t('button.cancel') }}</el-button>
      <!--保存按钮-->
      <el-button :loading="isRequesting" size="medium" type="primary" @click="save">
        {{ $t('button.save') }}
      </el-button>
    </span>
  </div>
</template>

<script>
import { ssPollPriceAdd } from '@/api/pool/ss'

export default {
  name: 'TecAdd',
  props: {
    projectList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      // 正在查询
      isRequesting: false,

      formData: {}
    }
  },
  methods: {
    async save() {
      try {
        this.isRequesting = true
        await ssPollPriceAdd(this.formData, { msgSuccess: true, msgError: true })
        this.$emit('save')
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    cancel() {
      this.$emit('cancel')
    }
  }
}
</script>
